package utils;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtils {
	
	private HibernateUtils(){}
	private static Configuration cfg = null;
	private static SessionFactory sessionFactory = null;
	static {
		Configuration cfg = new Configuration().configure();
		sessionFactory = cfg.buildSessionFactory();
	}
	
	public static SessionFactory getSessionFactory(){
		
		return (sessionFactory == null ? cfg.buildSessionFactory() : sessionFactory);
	}
	
	public static Session getSession(){
		
		return getSessionFactory().openSession();
	}
	
	public static Configuration getConfiguration(){
		return cfg;
	}
}
